@echo off
:: MXSPLI-ShareMX
:: MixSoft Programming Language Interpreter
:: Version v12_ShareMXv3
:: Developers: Mihail Mojsoski
set debugpath=debug\debug.log
set mypath=%~dp0
cd %~dp1
set version=1.1.1A
set vbeta=1.1.0B
path %mypath%;%path%
set file=%~1
set args=%~2;%~3;%~4;%~5;%~6;%~7;%~8;%~9
set ext=mcode
call "%mypath%\lang.bat"
if "%~1"=="--vercheck" goto end
if "%~2"=="--debug" set debug=1
:start
set toexecute=0
set reset=0
set open=0
set sError=0
set line=1
set cnt=0
set endprog=0
for /f %%a in ('type "%file%"^|find "" /v /c') do set /a cnt=%%a
if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_DBG1% %cnt% %LNG_DBG2% "%file%" >> "%mypath%\%debugpath%"
if exist "%file%" goto PharseA
call :Error 01
goto end

:PharseA
for /F "skip=%line% tokens=*" %%A in (%file%) do (
	set /a line=%line%+1
	call :ProcessA %%A
	if "%line%"=="%cnt%" goto sA
	goto PharseA
)
:sA
set /p first=<%file%
set line=1
call :ProcessA %first%
call :Process %first%
if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_DBG1% %sopen% %LNG_DBG3% "%file%" >> "%mypath%\%debugpath%"
goto Pharse

:Pharse
if "%reset%"=="1" goto start
for /F "skip=%line% tokens=*" %%A in (%file%) do (
	set /a line=%line%+1
	if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_DBG5% %LNG_ATLINE% %LINE%: %%A >> "%mypath%\%debugpath%"
	if "%endprog%"=="1" goto s
	call :Process %%A
	if "%line%"=="%cnt%" goto s
	goto Pharse
)
:s
if not "%sError%"=="0" (
	if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_DBG4% %sError% >> "%mypath%\%debugpath%"
	call :Error 03 %sError%
	goto end
)
if not "%sopen%"=="0" (
	call :Error 02 %open%
	goto end
)
goto end

:ProcessA
if "%~1"=="code" call :seta %*
if "%1"=="[" set /a sopen=%sopen%+1
if "%1"=="]" set /a sopen=%sopen%-1
goto :end

:seta
if "%fname%"=="Main" set main=%line%
if "%fname%"=="main" set main=%line%
set fname=%~2
set f%fname%=%line%
set endcode=%open%
set pmode=code
goto end

:Process
call "%mypath%\proc.bat" %*
goto end

:Error
if "%~1"=="01" (
	echo %LNG_FILENOTEXIST%
	if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_FILENOTEXIST% >> "%mypath%\%debugpath%"
) else (
	if "%~1"=="02" (
		echo %LNG_UNEXPECTEDEND%
		if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_UNEXPECTEDEND% >> "%mypath%\%debugpath%"
	) else (
			if "%~1"=="03" (
			echo %LNG_FOUND% "%~1" %LNG_ERRORLASTERROR% 
			if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_FOUND% "%~1" %LNG_ERRORLASTERROR% >> "%mypath%\%debugpath%"
			echo %lasterror%
		) else (
			echo %LNG_UNKNOWNERROR% %~1
			if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_UNKNOWNERROR% %~1 >> "%mypath%\%debugpath%"
		)
	)
)
goto end

:end